<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <canvas id="canvas" width="600" height="400"></canvas>
  <script>
     /** @type {HTMLCanvasElement} */
     var canvas=document.querySelector("#canvas")
    var ctx=canvas.getContext("2d")
    var i=0.01
   var time= setInterval(function(){
    // ctx.clearRect(0,0,600,400)
    // clearInterval(time)
    i=i+0.01
    if(i>=1.00){
      i=0.01
      // clearInterval(time)
      
    }
    // console.log(i);
    
    var color=ctx.createLinearGradient(0,0,400,600)
    color.addColorStop(0,"blue")
    color.addColorStop(1,"red")
    color.addColorStop(i,"yellow")
    
    ctx.fillStyle=color
    ctx.fillRect(0,0,600,400)
    
   },10)
  </script>
</body>
</html>